import Taro, { Component } from '@tarojs/taro'
import { AtModal, AtModalContent, AtModalAction } from 'taro-ui'
import classnames from 'classnames'
import PropsType from 'prop-types'
import { View, Text, Button } from '@tarojs/components'
import '../styles/modal.scss'


export default class DModal extends Component {

    onCancel() {
        this.props.onCancel && this.props.onCancel()
    }

    onFirst(e) {
        e.stopPropagation()
        this.props.onFirst && this.props.onFirst()
    }

    onLast(e) {
        e.stopPropagation()
        this.props.onLast && this.props.onLast()
    }

    render() {
      const {
        className,
        isShow,
        title,
        text,
        firstbtn,
        lastbtn,
        isOver
      } = this.props
        return (
          <View className={classnames('b_modal', className)}>
            <AtModal isOpened={isShow} closeOnClickOverlay={isOver} className='b_modal__body' onClose={this.onCancel.bind(this)}>
              <AtModalContent className='b_modal__body_text'>
                <Text className='b_modal__body_title'>{title}</Text>
                {text}
              </AtModalContent>
              <AtModalAction className='b_modal__body_btn'>
                {firstbtn&&<Button onClick={this.onFirst.bind(this)} className='b_modal__body_cancel'>{firstbtn}</Button>}
                <Button onClick={this.onLast.bind(this)} className='b_modal__body_confirm'>{lastbtn}</Button>
              </AtModalAction>
            </AtModal>
          </View>
         
        )
    }
}

DModal.defaultProps = {
    className: '',
    isShow:false,
    isOver:true,
    title:'提示',
    text:'内容',
    firstbtn:'取消',
    lastbtn:'确定',
    onCancel: () => { },
    onFirst: () => { },
    onLast: () => { }
}
DModal.PropsType = {
    className: PropsType.oneOfType[PropsType.string, PropsType.object],
    isShow:PropsType.bool,
    isOver:PropsType.bool,
    title: PropsType.string,
    text: PropsType.string,
    firstbtn: PropsType.string,
    lastbtn: PropsType.string,
    onCancel: PropsType.func,
    onFirst: PropsType.func,
    onLast: PropsType.func
}